local 当前 = 多开数据.当前
local 可收购物品 = {
    [1]={类型="杂货",道具表={}},
    [2]={类型="宝石",道具表={}},
    [3]={类型="精魄灵石",道具表={}},
    [4]={类型="未激活的星石",道具表={}},
    [5]={类型="魔兽要诀",道具表={}},
    [6]={类型="高级魔兽要诀",道具表={}},
    [7]={类型="特殊魔兽要诀",道具表={}},
    [8]={类型="制造指南书",道具表={}},
    [9]={类型="灵饰指南书",道具表={}},
    [10]={类型="精铁,晶石",道具表={}},
    [11]={类型="召唤兽内丹",道具表={}},
    [12]={类型="法宝材料",道具表={}}
}
local 临时名称 = {"战魄","无级别宝珠","附魔宝珠","天赋符","超简易宝珠","灵犀之屑"
,"炼兽真经","神兜兜","九转金丹","修炼果","天蚕丝"}
for i=1,#临时名称 do
    if 临时名称[i]== "战魄"  or 临时名称[i]== "附魔宝珠"then
        local 临时表 = {名称=临时名称[i],重点="160级"..临时名称[i]}
        table.insert(可收购物品[1].道具表, 临时表)
    else
        local 临时表 = {名称=临时名称[i]}
        table.insert(可收购物品[1].道具表, 临时表)
    end
end
local 临时名称 = {"星辉石","钟灵石","月亮石","太阳石","舍利子","红玛瑙","黑宝石","光芒石","神秘石"}
local 临时分类 = {"健步如飞","血气方刚","回春之术","锐不可当","心源","通真达灵","心无旁骛","风雨不动","回若金汤","气壮山河"}
for i=1,#临时名称 do
    for k=1,15 do
    if 临时名称[i]== "钟灵石" then
        for n=1,#临时分类 do
        local 临时表 = {名称=临时名称[i],重点=k.."级"..临时分类[n]}
        table.insert(可收购物品[2].道具表, 临时表)
        end
    else
        local 临时表 = {名称=临时名称[i],重点=k.."级"}
        table.insert(可收购物品[2].道具表, 临时表)
        end
    end
end
local 临时名称 = {"精魄灵石"}
local 临时类型 = {"速度","躲避","伤害","灵力","防御","气血"}
for i=1,#临时名称 do
    for k=1,15 do
        for n=1,#临时类型 do
            local 临时表 = {名称=临时名称[i],重点=k.."级"..临时类型[n]}
            table.insert(可收购物品[3].道具表, 临时表)
        end
    end
end
local 临时名称 = {1,2,3,4,5,6}
for i=1,#临时名称 do
    可收购物品[4].道具表[i] = {名称="未激活的星石",重点=取星石部位(临时名称[i])}
end

local 临时名称 = {"防御","反击","必杀","吸血","强力","偷袭","反震","法术暴击","冥思","法术波动",
             "夜战","隐身","感知","再生","法术连击","毒","幸运","连击","永恒","敏捷","神佑复生","驱鬼","鬼魂术",
             "魔之心","水攻","落岩","雷击","烈火","火属性吸收","土属性吸收","水属性吸收","雷属性吸收","迟钝","招架","神迹","精神集中","盾气","合纵","否定信仰","飞行"}
for i=1,#临时名称 do
    可收购物品[5].道具表[i] = {名称="魔兽要诀",重点=临时名称[i]}
end

local 临时名称 = {"高级防御","高级反击","高级必杀","高级吸血","高级强力","高级偷袭","高级盾气","高级神迹","高级合纵","高级招架","高级精神集中","高级反震","高级法术暴击","高级冥思","高级否定信仰","高级法术波动","高级夜战","高级隐身","高级感知","高级再生","高级法术连击","高级毒","高级幸运","高级连击","高级永恒","高级敏捷","高级神佑复生","高级驱鬼","高级鬼魂术","高级魔之心","水漫金山","泰山压顶","地狱烈火","奔雷咒","高级飞行","高级慧根"}
for i=1,#临时名称 do
    可收购物品[6].道具表[i] = {名称="高级魔兽要诀",重点=临时名称[i]}
end

local 临时名称 = {"死亡召唤","惊心一剑","苍鸾怒击","夜舞倾城","净台妙谛","龙魂","凝光炼彩","独行","诸天正法","浮云神马","须弥真言","剑荡四方",
"移花接木","出其不意","势如破竹","灵山禅语","无畏布施","灵能激发","大快朵颐","从天而降","理直气壮","津津有味","昼伏夜出","神出鬼没","溜之大吉","虎虎生风",
"八凶法阵","天降灵葫","月光","食指大动","流沙轻音","叱咤风云","神来气旺","千钧一怒","凭风借力","风起龙游","欣欣向荣","柳暗花明","乘胜追击","法术防御",
"气贯长虹","义薄云天","与生俱来","薪火相传","拘魂索命","力劈华山","善恶有报","上古灵符","顾盼生姿"}
for i=1,#临时名称 do
    可收购物品[7].道具表[i] = {名称="高级魔兽要诀",重点=临时名称[i]}
end
local 临时名称 = {"剑","扇","锤","枪","刀","斧","环","双","飘","棒","爪","鞭","伞","巨剑","宝珠","法杖","弓弩","灯笼","项链","鞋子","男衣","女衣","头盔","发钗","腰带"}
for i=1,#临时名称 do
    for k=8,15 do
        local 临时表 = {名称="制造指南书",重点=(k*10).."级"..临时名称[i]}
        table.insert(可收购物品[8].道具表, 临时表)
    end
end
local 临时名称 = {"手镯","佩饰","戒指","耳饰"}
local 临时等级 = {6,8,10,12,14,16}
for i=1,#临时名称 do
    for n=1,#临时等级 do
        local 临时表 = {名称="灵饰指南书",重点=(临时等级[n]*10).."级"..临时名称[i]}
        table.insert(可收购物品[9].道具表, 临时表)
    end
end
local 临时名称 = {"百炼精铁","元灵晶石"}
local 临时等级 = {6,8,10,12,14,16}
for i=1,#临时名称 do
    if 临时名称[i] == "百炼精铁" then
        for k=8,15 do
            local 临时表 = {名称="百炼精铁",重点=(k*10).."级"}
            table.insert(可收购物品[10].道具表, 临时表)
        end
    elseif 临时名称[i] == "元灵晶石" then
        for n=1,#临时等级 do
            local 临时表 = {名称="元灵晶石",重点=(临时等级[n]*10).."级"}
            table.insert(可收购物品[10].道具表, 临时表)
        end
            --table.insert(可收购物品[10].道具表, 临时表)
    end
end
local 临时名称 = {"迅敏","狂怒","阴伤","静岳","擅咒","灵身","矫健","深思","钢化","坚甲","慧心","撞击","无畏","愤恨","淬毒","狙刺","连环","圣洁","灵光","神机步","腾挪劲","玄武躯","龙胄铠","玉砥柱","碎甲刃","阴阳护","凛冽气","舍身击","电魂闪","通灵法","双星爆","催心浪","隐匿击","生死决","血债偿"}
for i=1,#临时名称 do
    if i<=19 then
        可收购物品[11].道具表[i] = {名称="召唤兽内丹",重点=临时名称[i]}
    else
        可收购物品[11].道具表[i] = {名称="高级召唤兽内丹",重点=临时名称[i]}
    end
end
local 临时名称 = {"玄龟板","阴沉木","麒麟血","内丹","金凤羽","补天石","龙之筋"}
local 临时五行 = {"金","木","水","火","土"}
for i=1,#临时名称 do
    for n=1,#临时五行 do
        local 临时表 = {名称=临时名称[i],重点=临时五行[n]}
        table.insert(可收购物品[12].道具表, 临时表)
    end
end

local 收购发布 = 多开数据[多开数据.当前].__UI界面.窗口层:创建我的窗口("收购发布",0,0,773,440)
function 收购发布:初始化()
    字体28 = require("SDl.文字")("assets/hkyt.ttf", 28, true):置颜色(__取颜色("红色"))
    __置窗口坐标(self,'中')
    local nsf = require('SDL.图像')(773,440)
    if nsf:渲染开始() then
        置窗口背景("发布收购",0,12,766,430,true):显示(0,0)
        取白色背景(0, 0, 260, 320, true):显示(21,50)
        取灰色背景(0,0,260,50,true):拉伸(258,30):置透明(100):显示(21,52)
        字体16:置颜色(__取颜色('白色'))
        字体16:取图像("求购区"):显示(31,60)
        字体16:取图像("价格"):显示(200,60)

        取白色背景(0, 0, 180, 240, true):显示(290,50)
        取灰色背景(0,0,180,50,true):拉伸(180,30):置透明(100):显示(290,52)
        字体16:取图像("道具类型"):显示(330,60)

        取白色背景(0, 0, 255, 240, true):显示(480,50)
        取灰色背景(0,0,255,50,true):拉伸(255,30):置透明(100):显示(480,52)

        字体16:取图像("详细道具"):显示(490,60)

        字体16:取图像("收购数量"):显示(290,300)
        取输入背景(0, 0, 100, 23):显示(360, 300)

        字体16:取图像("收购单价"):显示(290,330)
        取输入背景(0, 0, 100, 23):显示(360, 330)

        字体16:取图像("收购总价"):显示(290,360)
        取输入背景(0, 0, 100, 23):显示(360, 360)

        字体16:取图像("招  牌"):显示(490,300)
        取输入背景(0, 0, 100, 23):显示(560, 300)

        字体16:取图像("手续费"):显示(490,330)
        取输入背景(0, 0, 100, 23):显示(560, 330)

        字体16:取图像("现  金"):显示(490,360)
        取输入背景(0, 0, 100, 23):显示(560, 360)
        
        nsf:渲染结束()
    end
    self:置精灵(nsf:到精灵())
end

function 收购发布:打开(data)
    self.选中类型 = 0
    self.收购列表:重置()
    self.数据 = data
    self.招牌:置文本(data.收购数据.名称)
    self:置可见(true)
end

function 收购发布:显示(x,y)
    if tonumber(收购发布.收购数量:取文本()) and tonumber(收购发布.收购单价:取文本()) then
        字体16:置颜色(__取颜色('红色')):取精灵(tonumber(收购发布.收购数量:取文本())*tonumber(收购发布.收购单价:取文本())):显示(x+370,y+362)
        local 手续费 = math.ceil(tonumber(收购发布.收购单价:取文本())*0.5)
        if 手续费 < 5000 then 手续费 = 5000 end
        字体16:置颜色(__取颜色('红色')):取精灵(手续费):显示(x+570,y+332)
    end
    字体16:置颜色(__取颜色('绿色')):取精灵(收购发布.数据.银子):显示(x+570,y+362)
end

local 招牌 = 收购发布:创建输入("招牌",570,302,90,18)
function 招牌:初始化()
    self:取光标精灵()
    self:置限制字数(12)
    self:置颜色(__取颜色('黑色'))
end

local 收购数量 = 收购发布:创建输入("收购数量",370,302,90,18)
function 收购数量:初始化()
    self:取光标精灵()
    self:置限制字数(3)
    self:置颜色(__取颜色('黑色'))
end

local 收购单价 = 收购发布:创建输入("收购单价",370,332,90,18)
function 收购单价:初始化()
    self:取光标精灵()
    self:置限制字数(12)
    self:置颜色(__取颜色('黑色'))
end


local 收购列表 = 收购发布:创建列表("收购列表",300,90,165,190)

function 收购列表:初始化()
    self:置文字(字体18)
    self.行间距 = 10
end

function 收购列表:重置()
    收购列表:清空()
    收购列表:置颜色(__取颜色('黑色'))
    for i = 1,#可收购物品 do
        收购列表:添加(可收购物品[i].类型)
    end
end

function 收购发布:刷新求购道具(data)
    self.已收购数据 = data
    收购发布.已收购网格:置物品(data)
end

function 收购列表:左键弹起(x, y, i, item, msg)
    收购发布.选中类型 = i
    收购发布.收购网格:置物品(可收购物品[i].道具表)
end

local 已收购网格 = 收购发布:创建我的网格("已收购网格",30,90,240,190,230,55,13,13,30,1,true)

function 已收购网格:左键弹起(x, y, a, b, msg)
    if self.子控件[a] and self.子控件[a]._spr and self.子控件[a]._spr.物品 then
        if 收购发布.已收购选中 then
            self.子控件[收购发布.已收购选中]._spr.确定 = nil
        end
        收购发布.已收购选中 = a
        self.子控件[收购发布.已收购选中]._spr.确定 = true
    end
end

function 已收购网格:置物品(data)
    for i = 1,#self.子控件 do
        local lssj = __物品格子.创建(当前)
        if data[i] then
            lssj:置物品(data[i],"白格子","已收购网格",data[i].名称)
            self.子控件[i]:置精灵(lssj)
        else
            self.子控件[i]:置精灵(nil)
        end
    end
end


local 收购网格 = 收购发布:创建我的网格("收购网格",490,90,240,190,230,55,13,13,30,1,true)

function 收购网格:左键弹起(x, y, a, b, msg)
    if self.子控件[a] and self.子控件[a]._spr and self.子控件[a]._spr.物品 then
        if 收购发布.选中 then
            self.子控件[收购发布.选中]._spr.确定 = nil
        end
        收购发布.选中 = a
        self.子控件[收购发布.选中]._spr.确定 = true
        收购发布.收购单价:置文本("")
        收购发布.收购数量:置文本("")
    end
end

function 收购网格:置物品(data)
    for i = 1,#self.子控件 do
        local lssj = __物品格子.创建(当前)
        if data[i] then
            lssj:置物品(data[i],"白格子","收购道具",data[i].名称)
            self.子控件[i]:置精灵(lssj)
        else
            self.子控件[i]:置精灵(nil)
        end
    end
end

local 关闭 = 收购发布:创建我的按钮(__res:getPNGCC(1,401,0,46,46),"关闭",723,0)
function 关闭:左键弹起(x,y,msg)
    收购发布:置可见(false)
end

local 发布求购 = 收购发布:创建我的按钮(__res:getPNGCC(3,2,507,124,41,true):拉伸(123,41),"发布求购",590,390,"发布求购")
function 发布求购:左键弹起(x,y,msg)
    if 收购发布.选中 and 收购发布.选中类型 then
        if tonumber(收购发布.收购数量:取文本()) and tonumber(收购发布.收购单价:取文本()) then
            发送数据(当前,3720.2,{名称=可收购物品[收购发布.选中类型].道具表[收购发布.选中].名称,重点=可收购物品[收购发布.选中类型].道具表[收购发布.选中].重点 or "",单价=tonumber(收购发布.收购单价:取文本()),数量=tonumber(收购发布.收购数量:取文本())})
        else
            多开数据[当前].__UI弹出.提示框:打开('#Y请输入正确的收购数量和收购单价')
        end
    end
end

local 更改招牌 = 收购发布:创建我的按钮(__res:getPNGCC(3,2,507,124,41,true):拉伸(123,41),"更改招牌",410,390,"更改招牌")
function 更改招牌:左键弹起(x,y,msg)
    if 收购发布.招牌:取文本() ~= "" then
        发送数据(当前,3720.4,{名称=收购发布.招牌:取文本()})
    end
end


local 删除求购 = 收购发布:创建我的按钮(__res:getPNGCC(3,2,507,124,41,true):拉伸(123,41),"删除求购",50,390,"删除求购")
function 删除求购:左键弹起(x,y,msg)
    if 收购发布.已收购选中 and 收购发布.已收购数据[收购发布.已收购选中] then
        发送数据(当前,3720.3,{名称=收购发布.已收购选中})
    end
end

local 收摊回家 = 收购发布:创建我的按钮(__res:getPNGCC(3,2,507,124,41,true):拉伸(123,41),"收摊回家",230,390,"收摊回家")
function 收摊回家:左键弹起(x,y,msg)
    发送数据(当前,3720.5)
end